package com.zzb.framework.role.dao;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.zzb.framework.role.dao.mapper.SysRoleMapper;
import com.zzb.framework.role.entity.SysRole;
import com.zzb.framework.common.BaseDAO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 角色表 Dao接口
 */
@Repository
public class SysRoleDAO extends BaseDAO<SysRole> {
    @Autowired
    private SysRoleMapper sysRoleMapper;

    public SysRoleMapper getMapper() {
        return sysRoleMapper;
    }

    public List<SysRole> findByUserId(String userId) {
        return sysRoleMapper.findByUserId(userId);
    }

    /**
     * 通过角色码查询角色
     */
    public SysRole findByRoleCode(String roleCode) {
        return getMapper().selectList(new EntityWrapper<SysRole>()
                .eq("role_code", roleCode)
                .orderBy("create_time", false)
                .last("limit 1")).stream().findFirst().orElse(null);
    }

}
